package com.example.auction.service.impl;

import com.example.auction.context.BaseContext;
import com.example.auction.entity.Item;
import com.example.auction.entity.dto.ItemDTO;
import com.example.auction.mapper.ItemMapper;
import com.example.auction.service.ItemService;
import com.fasterxml.jackson.databind.util.BeanUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Slf4j
@Service
public class ItemServiceImpl implements ItemService {

    @Autowired
    private ItemMapper itemMapper;

    /*
     * 创建拍卖接口
     * */
    @Override
    public void createItem(ItemDTO itemDTO) {
        Item item = new Item();
        BeanUtils.copyProperties(itemDTO,item);
        item.setCreateTime(LocalDateTime.now());
        item.setUpdateTime(LocalDateTime.now());
        item.setCreateId(BaseContext.getCurrentId());
        item.setUpdateId(BaseContext.getCurrentId());
        itemMapper.insert(item);
    }

    /*
     * 根据id预览拍卖
     * */
    @Override
    public Item getItemById(Long id) {
        Item item = itemMapper.selectById(id);
        return item;
    }


}
